<%@page pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<link href="${ctx}/style/css.css" rel="stylesheet" type="text/css">
<script src="${ctx }/js/jquery1-11-11.min.js"></script>
<script type="text/javascript">
	var baseURL = "${ctx}"
	

	$(document).ready(function() {
		//绑定监听input属性改变事件
		$('#signCode').bind('input propertychange', function() {  
		   console.log($(this).val());
		   //8位数字正则表达式
		   var reg = new RegExp("^[0-9]*$");  
		   var signCode = $(this).val();
		   if(signCode.length == 8 && reg.test(signCode)){
			   console.log('成功进入签到码直接检验逻辑!');
			   $.ajax({"url" : "${ctx}/activiter/directSign", //路径
					   "cache" : false, //不缓存
					   "async" : true, //异步
					   "type" : "POST", //POST方式提交
					   "dataType" : "json", //json格式，重要
					   // "contentType": "application/json",	  //json格式
					   "data" : {
						  'signCode' : signCode
					   }, //要提交的数据对象
					   success : function(json) { //成功处理
						   console.log('处理成功!');
						   console.log(json);
						   searchqd();
						   if(json.msg !== undefined){
						      alertsimple(json.msg, 5000);
                              return;							   
						   }
						       var ar = json;
						       var mobile = ar.activiter_mobile;
							   console.log(mobile);
							   var name = ar.activiter_name;
							   console.log(name);
							   var sign_code = ar.sign_code;
							   console.log(sign_code);
								var enterprise = ar.enterprise;
								   console.log(enterprise);
								var sex = ar.sex;
								   console.log(sex);
								if(sex==1){
									sex="男";
								}else if(sex==0){
									sex="女";
								}else{
									sex="保密";
								}
								if(enterprise==null){
									enterprise="";
								}
							   console.log();
							   var oneContent = "<li><div>"
									+ name
									+ "</div><div>"
									+ mobile
									+ "</div><div>"
									+ sex
									+ "</div><div>"
									+ enterprise
									+ "</div><div>"
									+ sign_code
									+ "</div><div><a class='button' style='color:green' href='#'>已签到</a></div></li>";
							console.log(oneContent);
							$("#search_list ul").append(oneContent);
							 alertsimple('您已成功签到 ！', 5000);
					   },
					   error : function(x, e) { //异常处理
						console.log(x);
						console.log(e);
						console.log('处理失败');
					   }
				});
		   }
		});  

	    $('#signCode').keydown(function(){
		   var signCode = $('#signCode').val();
		   console.log(signCode);
		});
				
	    $('#searchSignMan').click(function() {
	    	alluser('0',1);
		});
	});

	console.log('启动定时刷新!');
	window.setInterval("startrequest()", 60000);
	
	function startrequest() {
		console.log('开始刷新');
		location.href = "${ctx}/activiter/content";
		console.log('刷新结束');
	}

	/*
	*清空列表数据
	*/
	function searchqd() {
		var lis = $('#search_list ul li');
		console.log(lis.size());
		for (var i = 1; i < lis.size(); i++) {
			lis.eq(i).empty().remove();
		}
		var searcheList = $("#search_list");
		searcheList.fadeIn(300);
	}
	
	//获取活动人员名单，通用逻辑
	function alluser(id,page){
		var signCode = $('#signCode').val();
		$.ajax({"url" : "${ctx}/activiter/list", //路径
				"cache" : false, //不缓存
				"async" : true, //异步
				"type" : "POST", //POST方式提交
				"dataType" : "json", //json格式，重要
				"data" : {
					page:page,
					flag:id,
					signCode:signCode
				}, //要提交的数据对象
				success : function(json) { //成功处理	
						var ary = json.list;	
				        var page=json.pageNumber;
				        var totalpage=json.totalPage;
				        $("#search_list ul").empty();
				        if(ary.length>0){
							for (var i = 0; i < ary.length; i++) {
								var activiter = ary[i];
								var mobile = activiter.activiter_mobile;
								var name = activiter.activiter_name;
								var sign_code = activiter.sign_code;
								var enterprise = activiter.enterprise;
								//var sex = activiter.sex;
								var sign_status = activiter.sign_status;
								console.log("sign_status: { "+ sign_status+" }");
								if(enterprise==null){
									enterprise="";
								}
								var oneContent = "<li><div>"
										+ name
										+ "</div><div>"
										+ mobile
										+ "</div><div>"
										+ enterprise
										+ "</div><div>"
										+ sign_code
										+ "</div><div>";
										
										//+"<a class='button' href= '"+ baseURL+ "/activiter/sign?name="+ name + "&mobile=" + mobile + "&signCode="+ sign_code + "'>签到</a>"
										var linkContent = "";
										if(sign_status){
										   linkContent = "<a class='button' style='color:green' href='#'>已签到</a>";
										}else{
										   linkContent = "<a class='button' href= '"+ baseURL+ "/activiter/sign?name="+ name + "&mobile=" + mobile + "&signCode="+ sign_code + "'>签到</a>";
										}
										oneContent += linkContent;
										oneContent += "</div></li>";
								$("#search_list ul").append(oneContent);
							}
				        }	
						$("#search_list").show();
						var shang;
						if(page==1){
							shang = page;
						}else{
							shang = page-1;
						}
						var xia;
						if(page==totalpage){
							xia = page;
						}else{
							xia = page+1;
						}
						var fyContent = "<b onclick='alluser("+id+","+shang+")'>上一页</b><span style='margin:0px 10px;'>"+page+"/"+totalpage+"</span><b onclick='alluser("+id+","+xia+")'>下一页</b>";
						$("#search_list #fy").empty();
						$("#search_list #fy").append(fyContent);

					}
				});
		}	
	  function innerSignCallBack(data){
		  console.log(data);
	  }
	  
	  function maskMobile(mobile){
		  if(mobile === undefined || mobile === ""){
			  return "";
		  }
		 // mobile.sub
	  }

</script>
<!--全诚字符图标-->
<link href="${ctx }/style/font.css" rel="stylesheet" type="text/css">
<style>
.qd_ul li div{width:20%;overflow:hidden;min-height:30px;height: 30px;}
</style>
</head>

<body>
	<!--左边代码-->
	<div class="left_con">
		<div class="hd_bt">
			<strong style="font-size: 16px">${activtites.activites_name}</strong><br>
			<!--   <span><i
				class="icon-quancheng72"></i>&nbsp;会议地点在此</span> <span><i
				class="icon-quancheng78"></i>&nbsp;2015-2-25&nbsp;&nbsp;9:00</span>-->
		</div>

		<div class="hd_con">
			<ul>
				<li style="border-right: #CCC 1px solid;"><b
					style="color: blue;cursor:pointer; " onclick="alluser(0,1)" 0>${totalActiviters}</b><br>报名人数</li>
				<li style="border-right: #CCC 1px solid;"><b
					style="color: green;cursor:pointer;" onclick="alluser(1,1)" >${signeders}</b><br>已签到</li>
				<li><b style="color: red;cursor:pointer;" onclick="alluser(2,1)" >${noSigneders}</b><br>未签到</li>
			</ul>
		</div>
		<!--清除浮动-->
		<div class="c"></div>

		<div class="hd_con" style="text-align: center; margin: 30px auto;">
			<span><a href="${ctx}/activiter/regist">现场报名</a></span>
		</div>

		<div class="hd_con">

			<div class="hd_qd">
				<input id="signCode" type="text"
					style="font-size: 22px; font-family: '微软雅黑'; padding-left: 10px;"
					title="输入短信签到码" placeholder="请输入签到码">
				
				<div class="tijiao">
					<i class="icon-quancheng134" title="点击执行签到" id="searchSignMan"></i>
				</div>
			</div>
		</div>
		<div class="hd_con1">
			<ul class="qd_ul">
				<li>
					<div>姓名</div>
					<div>电话</div>
					<div>企业</div>
					<div>签到码</div>
					<div>操作</div>
				</li>
		</div>
		<div class="hd_con1" id="search_list" style="display: none;">
			<ul class="qd_ul"></ul>
			<div id='fy' style='text-align:center; line-height:30px;'></div>
		</div>
	</div>
	<!--右边代码-->
	<div class="right_con">
	   <iframe src="${ctx}/activiter/signedMan" scrolling="auto" height="600" frameborder="0"></iframe>
	</div>
	<!--js弹出框功能-->
	<div id="insert" style="position: fixed; z-index: 2000;"></div>
	<script src="${ctx }/js/common.js"></script>
</body>
</html>
